<?php
// 转向页面， 负责根据不同的TokenType来用不同的方式展现
// Include All Header Files 
require ("./includes/pears.php");
// ui related 
require ("./includes/config.php");

// 输入的参数
if (!empty($_REQUEST['preview']))
{
    $preview = true;
}
else
{
    $preview = false;
}

if (!empty($_REQUEST['token']))
    $token = trim($_REQUEST['token']);

if (!empty($_REQUEST['token']))
{
    $token = trim($_REQUEST['token']);
    $info  = Facade::getUrlInfoByToken($token);

    if (!empty($info))
    {
        $has_info = true;
        $token_type = $info->get('token_type');
        $realurl    = $info->get('realurl');
        if ($preview) $token_type = TokenType::DUANURL_TT_PREVIEW;
    }
    else
    {
        // ERRORPAGE 错误页面
        die('无法获取该url');
    }

}
else
{
    // ERRORPAGE 显示出错
    die('没有token参数');
}



// 根据token_type选择不同的处理
switch ($token_type)
{
    case TokenType::DUANURL_TT_DEFAULT :
        // 默认的处理，进行302跳转 
        header("Location: $realurl");
        break;
    default :
        $preview = true;
        break;
}
?>
<html>
    <head>
        <title>短地址  <?php echo DUANURL_HOSTNAME; ?> | 预览</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <?php include('./includes/css.php');?>
    </head>
    <body class="preview">
      <div class="body">
        <?php include ("./includes/index_header.php"); ?>
        <?php include ("./includes/preview_body.php"); ?>
        <?php include ("./includes/footer.php");?>
      </div>
    </body>
</html>
